package com.yitiao.data_algorithms.leetcode.editor.cn;

import com.yitiao.data_algorithms.leetcode.editor.cn.base.TreeNode;

class SumOfLeftLeaves {
    // 2023-02-13 17:09:33
    public static void main(String[] args) {
        Solution solution = new SumOfLeftLeaves().new Solution();
    }

    //leetcode submit region begin(Prohibit modification and deletion)

    /**
     * Definition for a binary tree node.
     * public class TreeNode {
     * int val;
     * TreeNode left;
     * TreeNode right;
     * TreeNode() {}
     * TreeNode(int val) { this.val = val; }
     * TreeNode(int val, TreeNode left, TreeNode right) {
     * this.val = val;
     * this.left = left;
     * this.right = right;
     * }
     * }
     */
    class Solution {
        int sum = 0;

        public int sumOfLeftLeaves(TreeNode root) {
            dfs(root);
            return sum;
        }

        private void dfs(TreeNode root) {
            if (root == null) return;
            if (root.left != null && root.left.right == null && root.left.left == null) {
                sum += root.left.val;
            }
            dfs(root.left);
            dfs(root.right);
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}